package com.ccc.orm.util;

import org.apache.commons.beanutils.Converter;

import javax.xml.crypto.Data;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import static org.apache.commons.beanutils.ConvertUtils.register;

/**
 * 抽象基础工具类
 *
 * @author charry
 * @version 0.1
 * @since 2019/6/30 19:04
 */
public abstract class BaseUtils {

    static {
        register(new Converter() {
            @SuppressWarnings("unchecked")
            @Override
            public <T> T convert(Class<T> type, Object value) {
                Date date = null;
                DateFormat dateFormat = new SimpleDateFormat(
                        "yyyy-MM-dd HH:mm:ss");
                try {
                    date = dateFormat.parse((String) value);
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                return (T) date;
            }
        }, Data.class);
    }
}
